#pragma once

#include <vector>
#include <string>
#include <cstdint>
#include <iostream>

class TsvParser {
public:
    virtual ~TsvParser() {}

    bool loadFromMemory(const std::string &text);
    bool loadFromFile(const std::string &filename);
    inline size_t columns() const { return titles_.size(); }
    inline size_t rows() const { return content_.size(); }
    inline const std::string &title(size_t index) const {
        static std::string dummy;
        if (index >= titles_.size()) return dummy;
        return titles_[index];
    }
    inline const std::string &data(size_t r, size_t index) const {
        static std::string dummy;
        if (r >= content_.size()) return dummy;
        if (index >= titles_.size()) return dummy;
        return content_[r][index];
    }
    inline const std::vector<std::string> &row(size_t r) const {
        static std::vector<std::string> dummy;
        if (r >= content_.size()) return dummy;
        return content_[r];
    }

private:
    void loadFromStream(std::istream &is);

private:
    std::vector<std::string> titles_;
    std::vector<std::vector<std::string>> content_;
};
